package com.zhuzl.orderservice.service;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhuzl.orderservice.mapper.OrderMapper;
import com.zhuzl.orderservice.model.OrderInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.UUID;

/**
 * @author JZY001
 */
@Service
public class OrderService extends ServiceImpl<OrderMapper, OrderInfo> {


    @Transactional(rollbackFor = Exception.class)
    public void createOrder(Integer productId, Integer count, Boolean hasError) {
        OrderInfo order = new OrderInfo();
        order.setOrderNo(UUID.randomUUID().toString());
        order.setUserId("zhuzl");
        order.setProductId(productId);
        order.setCount(count);
        order.setAmount(count * 1.5);
        order.setCreateTime(LocalDateTime.now());
        super.save(order);

        // 产生异常
        if (hasError) {
            int x = 1 / 0;
        }
    }
}
